package ControlLayer;
import ModelLayer.*;
import java.util.Date;

public class OrderCtr
{
    private Order o;
   
    public OrderCtr()
    {
       Discounts.getInstance();
       Orders.getInstance();
       Products.getInstance();
       Items.getInstance();
       Customers.getInstance();
       PaymentTypes.getInstance();
       DeliveryTypes.getInstance();
       Staffs.getInstance();
       o = new Order();
    }

    public void createOrder(String _id, String _productId, String _itemId, String _customerId, String _deliveryTypeId, String _paymentTypeId, String _staffId)
    {
         o.setId(_id);
         Date sysDate = new Date();
         String dateString = sysDate.toString();
         o.setDateCreated(dateString);
         o.addProduct(Products.getProduct(_productId));
         o.setCustomer(Customers.getCustomer(_customerId));
         o.setPaymentType(PaymentTypes.getPaymentType(_paymentTypeId));
         if(_deliveryTypeId != "")
            o.setDeliveryType(DeliveryTypes.getDeliveryType(_deliveryTypeId));
         o.setStaff(Staffs.getStaff(_staffId));
         if(_itemId != "")
            o.addItem(Items.getItem(_itemId));
         o.setStatus("Created");
         Orders.addOrder(o);
    }
    
    public void addProduct(String _productId)
    {
        o.addProduct(Products.getProduct(_productId));
    }
    
    public void deleteProduct(String _productId)
    {
        o.removeProduct(_productId);
    }
    
    public void addItem(String _ItemId)
    {
        o.addItem(Items.getItem(_ItemId));
    }
    
    public void deleteItem(String _itemId)
    {
        o.removeItem(_itemId);
    }
    
    public double calculateSubtotal()
    {
        o.calculateSubtotal();
        return o.getSubtotal();
    }
    
    public double calculateTotal()
    {
        o.calculateTotal();
        return o.getTotalPrice();
    }
    
    public void deleteOrder(String _orderId)
    {
        Orders.getOrder(_orderId).setStatus("Deleted");
    }
    
    public void listAllOrders()
    {
        System.out.println("\nOrders:");
        for(int i = 0; i<Orders.getSize(); i++)
        {
            System.out.println("\nID: " + Orders.allOrders(i).getId());
            System.out.println("\nTotal Price: " + Orders.allOrders(i).getTotalPrice() + "\n");
        }
    }
    
    public void listAllProducts()
    {
        Products.printProducts();
    }
    
    public void listAllItems()
    {
        Items.listAllItems();
    }
    
    public void listAllCustomers()
    {
        Customers.printCustomers();
    }
    
    public void listAllPaymentTypes()
    {
        PaymentTypes.printPaymentTypes();
    }
    
    public void listAllDeliveryTypes()
    {
        DeliveryTypes.printDeliveryTypes();
    }
    
    public Order findOrder(String _orderId)
    {
        return Orders.getOrder(_orderId);
    }
    
    public void listAllStaffs()
    {
        Staffs.listAllStaffs();
    }
}
